package de.koller.nadir.render;

import de.koller.nadir.NNode;
import de.koller.nadir.render.robj.Floor;
import de.koller.nadir.render.texture.NTextures;
import de.koller.oceanFramework.tree.Child;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

public class NRender extends NNode {
	
	public final NTextures textures = new NTextures();
	
	public final Floor floor = new Floor();
	@Child public final NCamera camera = new NCamera();
	
	@Override
	protected void init() {
		super.init();
		
//		GL11.glEnable( GL11.GL_CULL_FACE );
//		GL11.glCullFace( GL11.GL_BACK );

		GL11.glEnable( GL11.GL_DEPTH_TEST );
		GL11.glDepthFunc( GL11.GL_LEQUAL );
		
		GL11.glAlphaFunc( GL11.GL_GREATER, 0.01f );
		GL11.glEnable( GL11.GL_ALPHA_TEST );
	}
	
	private void projSet() {
		GL11.glMatrixMode( GL11.GL_PROJECTION );
		GL11.glLoadIdentity();

		GL11.glOrtho(	-Display.getWidth() * .5f, 
						 Display.getWidth() * .5f, 
						-Display.getHeight() * .5f,
						 Display.getHeight() * .5f, 
						-1000, 1000 );
		
		GL11.glMatrixMode( GL11.GL_MODELVIEW );
		GL11.glLoadIdentity();
	}
	
	public void renderGame( int elapsedTime ) {		
		projSet();
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
		
		camera.transform();
		
		GL11.glColor3f( 1, 1, 1 );
		floor.render( this );
		
		camera.restore();
	}

}
